package com.test.event.service.impl;

import com.test.event.config.EventDispatcher;
import com.test.event.listener.EventListener;
import com.test.event.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EventServiceImpl implements EventService {

    private EventDispatcher eventDispatcher;

    @Autowired
    public void setEventDispatcher(EventDispatcher eventDispatcher) {
        this.eventDispatcher = eventDispatcher;
    }

    @Override
    public void subscribe(String serviceName, EventListener listener) {
        eventDispatcher.addListener(serviceName, listener);
    }

    @Override
    public void unsubscribe(String serviceName) {
        eventDispatcher.removeListener(serviceName);
    }
}
